﻿using System;

namespace XcoAppSpaces.Core.Ports
{
	/// <summary>
	/// Defines a causality which is used for error handling, with ports for exceptions and ack messages.
	/// </summary>
	public class Causality : ICausality
	{
		/// <summary>
		/// Creates a new causality.
		/// </summary>
		/// <param name="errorPort">The port to which exceptions should be posted.</param>
		public Causality(IPort<Exception> errorPort)
		{
			ExceptionPort = errorPort;
		}

		/// <summary>
		/// Creates a new causality.
		/// </summary>
		/// <param name="errorPort">The port to which exceptions should be posted.</param>
		/// <param name="ackPort">The port to which ack messages should be posted.</param>
		public Causality(IPort<Exception> errorPort, IPort<Ack> ackPort)
		{
			ExceptionPort = errorPort;
			AckPort = ackPort;
		}

		/// <summary>
		/// The exception port of the causality. When an exception is not handled within the processing method of a port, it is posted to this exception port.
		/// </summary>
		public IPort<Exception> ExceptionPort { get; private set; }
		
		/// <summary>
		/// The ack port of the causality. An ack is posted either when a message was transferred successfully to another space, or when it was locally processed successfully.
		/// </summary>
		public IPort<Ack> AckPort { get; private set; }
	}
}